package com.shmilyou.dissertationmanagement.web;
/* Created with 岂止是一丝涟漪     530060499@qq.com    2019/2/27 */

import com.shmilyou.dissertationmanagement.resolver.LoginUser;
import com.shmilyou.dissertationmanagement.utils.ConfigUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ManagerController {
    private final Logger log = LoggerFactory.getLogger(ManagerController.class);

    @RequestMapping(value = "/manager", method = RequestMethod.GET)
    public String index(LoginUser loginUser, ModelMap map) {
        if (loginUser == null || loginUser.getId() < 0) {
            map.put("msg", "当前用户无权限");
            return "error";
        }
        map.put("debug", ConfigUtils.getDebug());
        map.put("anonymous", ConfigUtils.getAnonymous());
        return "manager";
    }

    @RequestMapping(value = "/manager/anonymous/enable", method = RequestMethod.GET)
    public String anonymousEnable() {
        ConfigUtils.anonymous = true;
        return "redirect:/manager";
    }

    @RequestMapping(value = "/manager/anonymous/disable", method = RequestMethod.GET)
    public String anonymousDisable() {
        ConfigUtils.anonymous = false;
        return "redirect:/manager";
    }

    @RequestMapping(value = "/manager/debug/enable", method = RequestMethod.GET)
    public String debugEnable() {
        ConfigUtils.debug = true;
        return "redirect:/manager";
    }

    @RequestMapping(value = "/manager/debug/disable", method = RequestMethod.GET)
    public String debugDisable() {
        ConfigUtils.debug = false;
        return "redirect:/manager";
    }
}
